<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/WEB-INF/views/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<style type="text/css">
	</style>
  <script type="text/javascript">
	var datagrid;
	var rowEditor=undefined;
	var buttonFlag = null;
	var userid=${sessionScope.user.id};
	$(function(){
		datagrid=$("#dg").datagrid({
			url:"${cs}/cs/credit/loanbid/list?state=4&&crediter="+userid,//加载的URL
		    isField:"id",
			pagination:true,//显示分页
			pageSize:10,//分页大小
			pageList:[10,15,20],//每页的个数
			fit:true,//自动补全
			fitColumns:true,
			iconCls:"icon-save",//图标
			columns:[[      //每个列具体内容
		              {field:'id', hidden:true },   
		              {field:'title', title:'标名',width:"10%",align:'center' },
		              {field:'content', title:'内容',width:"15%",align:'center' },
		              {field:'publisherName', title:'发布者账户',width:"10%",align:'center' },
		              {field:'securityName', title:'担保账户',width:"10%",align:'center' },
		              {field:'money', title:'借款金额',width:"10%",align:'center' ,
		            	  formatter: function(val,row, index) {
			            		return "￥"+val;
			            	} 
		              },
		              {field:'months', title:'贷款期限',width:"10%",align:'center',
		            	  formatter: function(val,row, index) {
			            		return val+"个月";
			            	}   
		              },
		              {field:'interest', title:'月息百分比',width:"15%",align:'center',
		            	  formatter: function(val,row, index) {
			            		return val*100+"%";
			            	}   
		              },
		              {field:'profit', title:'可获利',width:"10%",align:'center',
		            	  formatter: function(val,row, index) {
			            		return "￥"+(row.money*row.months*row.interest);
			            	}   
		              },
		              {field:'credittime', title:'资金到账时间',  width:"15%", align:'center',
		            	  formatter:function(value,row,rowIndex) { 
		            		  if(row.state>3&& row.state!=9){
		            		  var date = new Date(value);//long转换成date
		                      var month = (date.getMonth() + 1);
		                      var day = date.getDate().toString();
		                      if (month < 10) {
		                          month = "0" + month;
		                      }
		                      if (day < 10) {
		                          day = "0" + day;
		                      }
		                      return date.getFullYear().toString() + "年" + month + "月" + day+"日"+date.getHours()+"时"+date.getMinutes()+"分"+date.getSeconds()+"秒";
		            		 } 
		            	} 
			         },
			         {field:'crediterName', title:'放款账户',width:"10%",align:'center' }
		          ]],
			toolbar:[       
			        {text:"转让此债权",iconCls:"icon-redo",handler:function(){
			        	buttonFlag="edit";
			        	var rows=datagrid.datagrid('getSelections');
			        	if(rows.length==1)
			        	{
			        		if(rows[0].crediter==userid && rows[0].state==4){
			        			$('#dd').dialog('open');
			        			$('#id').val(rows[0].id);
			        			$("#title").textbox("setValue",rows[0].title);
			        			$("#content").textbox("setValue",rows[0].content);
			        			$("#money").numberbox("setValue",rows[0].money);
			        			$("#port").textbox("setValue",rows[0].money*rows[0].months*rows[0].interest+rows[0].money+"元");
			        		}else{
			        			$.messager.alert('错误', "您只能操作自己自己放贷的贷款标！", 'error');
			        		}
			        	} else {
			        		$.messager.alert('错误', "只能选择一个数据进行修改", 'error');
			        	}
			        }}
			  ],
				onLoadSuccess:function(data){
				   	  $('.function').linkbutton({
				   	      iconCls: 'icon-edit'
				   	  });
			   	  }
		});
		 $('#dd').dialog({
             title: "核对您的信息:",
             closed:true,
             modal: true, //dialog继承自window，而window里面有modal属性，所以dialog也可以使用
             toolbar: [{
					text:'Ok',
				iconCls:'icon-ok',
				handler:function(){
					var param = $("#ff").serializeJson();
					$.post("${cs}/cs/credit/loanbid/totransfer",param,function(r){
						$.messager.show({
							msg :r.msg,
							title : r.state>0?"Success！":"Error！"
						});
						$('#dd').dialog('close');
					},"json")
				}
			},{
				text:'Cancel',
				handler:function(){
					$('#dd').dialog('close');
					$('#ff').form('clear');
				}
			}],
			onClose: function() {
				$('#ff').form('clear');
				datagrid.datagrid('unselectAll');
				datagrid.datagrid('reload');
			}
         });
		 $("#btn_search").click(function(){
				var param = $("#searchForm").serializeJson();
				datagrid.datagrid('load', param);
			});
		$.extend($.fn.validatebox.defaults.rules, {     
	     username: {     
		        validator: function(value,param){    
		        	var flag=false;
		        	$.ajax({
		        		type:"post",
		        		url:"${cs}/exitsUsername",
		        		data:"username="+value,
		        		dataType:"json",
		        		async : false,
		        		success:function(result){
    	    				flag=!result;
    	    			}
		        	})
		        	return flag==true?true:false; 
		        },     
		        message: '对方账户信息不存在！'    
		    },
		    phone:{     
		        validator: function(value,param){
		        	var flag=/^1[3|4|5|8][0-9]\d{4,8}$/.test(value);
		        	return flag==true?true:false; 
		        },     
		        message: '手机号不合法!'    
		    },
		    equalTo: { validator: function (value, param) { return $(param[0]).val() == value; }, message: '两次输入密码不一致！' }
     	}); 
		 
	});
    </script>
</head>
<body style="padding:0 4px; margin:0;  overflow: hidden; ">
<div class="easyui-layout" style="width:100%;height:100%;" data-options="fit:true">
		<div title="债权转让:以下是您可转让债权信息！" data-options="region:'north'" style="height:70px">
		 <form id="searchForm" >
				<table cellpadding="5">
		    		<tr>
		    			<td>贷款标名:</td>
		    			<td><input class="easyui-textbox" type="text"   name="title" ></input></td>
		    			<td>内容关键字:</td>
		    			<td><input class="easyui-textbox" type="text"   name="content" ></input></td>
		    			<td ><a href="#" id="btn_search" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:80px">Search</a></td>
		    		</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center'" >
			<table id="dg" >
			</table>
		</div>
		<div id="dd" title="My Dialog"  style="width:300px;height:380px; text-align: center; " data-options="closed:true"> 
				    <form id="ff" >
				    		<input type="hidden" id="id" name="loanid">
				    		<div style="margin:10px 0">
								贷款标名:<input class="easyui-textbox" type="text" id="title" disabled="disabled" name="title" data-options="required:true"></input>
							</div>
							<div style="margin:10px 0">
								贷款内容:<input class="easyui-textbox" id="content" name="content" disabled="disabled" data-options="multiline:true,required:true"  style="width:171px;height:60px;">
							</div>
							<div style="margin:10px 0">
								贷款金额:<input class="easyui-numberbox" type="text" id="money" disabled="disabled" precision="2" name="money" min="0.01" data-options="required:true"></input>
							</div>
							<div style="margin:10px 0">
								可获利息本金和:<input class="easyui-textbox" type="text" id="port"  disabled="disabled"></input>
							</div>
							<div style="margin:10px 0">
								对方账户:<input class="easyui-textbox" id="content" name="otherUsername" data-options="required:true,validType:['length[4,15]','username']" >
							</div>
							<div style="margin:10px 0">
								您的密码:<input class="easyui-textbox" type="password"  name="password" data-options="required:true"  >
							</div>
							<div style="margin:10px 0">
								您的手机:<input class="easyui-numberbox"  name="phone" data-options="required:true,validType:['length[11,11]','phone']"  >
							</div>
							<div style="margin:10px 0">
								您的邮箱:<input class="easyui-textbox"  name="email" data-options="required:true" validType="email" >
							</div>
				    </form>
			</div>
		</div>
</body>
</html>